////////////////////////////
/** \file OzZerror.h
 *	OzZ Error Handling
 *	Include OzZcontrols.h to your project instead!\n
 *	This contains the error-handling routines and stringtable\n
 *	(c) Copyright by Daniel Bulla 2006
 *	\author Daniel 'OzZ' Bulla
 */

///@name Error-Types
///@{
#define ERRTYPE_NOERROR		0x00000000	///< everything is fine!
#define ERRTYPE_APPLICATION	0x0000000f	///< bug in program
#define ERRTYPE_MACHINE		0x000000f0	///< incompatibility
#define ERRTYPE_USER		0x00000f00	///< user did wrong input!
#define ERRTYPE_UNKNOWN		0x0000f000	///< unknown exception
///@}
///@name Error-Reasons
///@{
#define ERROR_UNKNOWN				-1
#define ERROR_NOTENOUGHMEMORY		 1

#define ERROR_NOTINITIALIZED		 2
#define ERROR_NOTREADY				 3
///@}

///@name Ready-to-use Error-Handelers
///@{
/// defines retry-entry-point
/**	defines the entry-point for a second (or third or...) try, if an error occurs and the user decides to retry
 *	\sa RETRY_END(error)
 */
#define RETRY_START do{
/// defines the end of the retry-entry-point
/**	
 *	\sa Has to follow after RETRY_START()
 */
#define RETRY_END(error) }while((MSGBTN_RETRY && HandleError(error)) != 0);
#define HandleCoreError(lookup, pointer) HandleError(Error(lookup, pointer, __LINE__, __FILE__, __FUNCTION__))
#define HandleCoreError_Ex(type, buttons, pos, reason, userinfo, pointer) HandleError(Error(type, buttons, pos, reason, userinfo, pointer, __LINE__, __FILE__, __FUNCTION__))
#define HandleCoreErrorBETA(sz) HandleError(Error(sz, __LINE__, __FILE__, __FUNCTION__))
///@}

namespace oc
{

struct Error
{
	const char*	szBETASTRING;
	int			tableLookup;///< lookup error in stringtable?
	int			type;		///< which kind of error is it? machine to slow? bug in app?
	DWORD	msgbtns;	///< which possibilies has the user to react?
	const char* szPos;		///< what wanted the App to do ? e.g. "Memory Allocation"
	const char* szReason;	///< what happened? e.g. "Not enough Memory avaliable"
	const char*	szForUser;	///< What did the User do wrong and what could he do against it? e.g. "Close some other Applications!"
	const char* szFile;		///< File
	const long   nLine;		///< Line in code
	const char* szFunction;	///< holds the name of the Function in which HanldeError was called
	void*		pointer;	///< for advanced information
	Error();
	Error(int lookup, void* p, const long line, const char* file, const char* func);
	/*BETA*/Error(const char* szBETA, const long line, const char* file, const char* func);
	Error::Error(int type, DWORD btns, const char* pos, const char* reason, const char* userinfo, void* p, const long line, const char* file, const char* func);
};

DWORD	HandleError(Error err);

}